View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: ServletView.java,v 1.9 2002/09/05 15:41:50 ludovicc Exp $ 37 */ 38 package org.scopemvc.view.servlet; 39 40 import java.util.Iterator; 41 import java.util.LinkedList; 42 import java.util.List; 43 import org.apache.commons.logging.Log; 44 import org.apache.commons.logging.LogFactory; 45 import org.scopemvc.core.Control; 46 import org.scopemvc.core.Controller; 47 import org.scopemvc.core.View; 48 import org.scopemvc.util.Debug; 49 50 /*** 51 * <P> 52 * 53 * A container View to aggregate a set of {@link Page}s the allows the currently 54 * visible Page to be set. </P> <P> 55 * 56 * In a servlet application, a Controller's View must 'contain' all the possible 57 * pages that the user could be interacting with because the user is free to hit 58 * the browser's forward and back buttons, use history or bookmarks etc. This 59 * "View" therefore acts as a simple container for other Views ({@link Page}s) 60 * that represent the actual interfaces that the user interacts with. It 61 * forwards any {@link #setController} and {@link #setBoundModel} calls to all 62 * children. </P> <P> 63 * 64 * A Controller in a web application must create an instance of ServletView to 65 * put all its possible Pages into using {@link #addPage}. The Controller then 66 * setView() establishes the container as the Controller's View. To determine 67 * the Page that is shown to the user on {@link 68 * org.scopemvc.controller.basic.BasicController#showView showView}, call {@link 69 * #setVisible} with the Page ID. </P> 70 * 71 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 72 * @created 05 September 2002 73 * @version $Revision: 1.9 $ $Date: 2002/09/05 15:41:50 $ 74 */ 75 public class ServletView implements View { 76 77 private final static Log LOG = LogFactory.getLog(ServletView.class); 78 79 /*** 80 * The child Pages this ServletView contains. 81 */ 82 protected List pages; 83 84 /*** 85 * The subview that is "visible". ie the Page that will streamView to the 86 * user. 87 */ 88 private Page visible; 89 90 /*** 91 * Parent Controller for this View and all child Pages. 92 */ 93 private Controller controller; 94 95 /*** 96 * Bound model for this View and all child Pages. 97 */ 98 private Object model; 99 100 101 /*** 102 * Create a container for the Pages that a Controller manages. 103 */ 104 public ServletView() { } 105 106 107 // -------------- implement View ------------------ 108 109 /*** 110 * Gets the bound model 111 * 112 * @return The boundModel value 113 */ 114 public final Object getBoundModel() { 115 return model; 116 } 117 118 119 /*** 120 * Gets the controller 121 * 122 * @return The controller value 123 */ 124 public final Controller getController() { 125 return controller; 126 } 127 128 129 /*** 130 * Note that ServletViews inherit their parent's Controller. 131 * 132 * @param inControl TODO: Describe the Parameter 133 */ 134 public final void issueControl(Control inControl) { 135 if (LOG.isDebugEnabled()) { 136 LOG.debug("issueControl: parent controller: " + controller); 137 } 138 139 if (controller == null) { 140 throw new UnsupportedOperationException("Can't issue Control because can't find a Controller"); 141 } 142 143 controller.handleControl(inControl); 144 } 145 146 147 /*** 148 * Used by {@link org.scopemvc.controller.servlet.ScopeServlet#findDefaultPage 149 * ScopeServlet.findDefaultPage} . 150 * 151 * @return The firstPage value 152 */ 153 public final Page getFirstPage() { 154 if (pages == null || pages.size() < 1) { 155 return null; 156 } 157 return (Page) pages.get(0); 158 } 159 160 161 /*** 162 * Gets the visible 163 * 164 * @return The visible value 165 */ 166 public final Page getVisible() { 167 if (visible != null) { 168 return visible; 169 } 170 if (pages != null && !pages.isEmpty()) { 171 return (Page) pages.get(0); 172 } 173 return null; 174 } 175 176 177 /*** 178 * The passed model is bound to this view and to all children ServletViews 179 * as well. 180 * 181 * @param inModel The new boundModel value 182 */ 183 public final void setBoundModel(Object inModel) { 184 model = inModel; 185 } 186 187 188 /*** 189 * The parent Controller must register itself with the ServletView via this 190 * method in order to receive Controls from it. 191 * 192 * @param inController the parent Controller. 193 */ 194 public final void setController(Controller inController) { 195 if (LOG.isDebugEnabled()) { 196 LOG.debug("setController: " + inController); 197 } 198 199 controller = inController; 200 } 201 202 203 // ---------- Select the child that will be asked to streamView ---------- 204 205 /*** 206 * Sets the visible 207 * 208 * @param inViewID The new visible value 209 */ 210 public final void setVisible(String inViewID) { 211 Page view = findPageByID(inViewID); 212 if (view == null) { 213 throw new UnsupportedOperationException("Can't find View with ID: " + inViewID + " to make it visible."); 214 } 215 visible = view; 216 } 217 218 219 // -------------- view container ------------------ 220 221 /*** 222 * Adds an element to the Page attribute of the ServletView object 223 * 224 * @param inPage The element to be added to the Page attribute 225 */ 226 public final void addPage(Page inPage) { 227 228 if (pages == null) { 229 pages = new LinkedList(); 230 } 231 232 pages.add(inPage); 233 234 inPage.setParent(this); 235 236 if (visible == null) { 237 visible = inPage; 238 } 239 } 240 241 242 /*** 243 * TODO: document the method 244 * 245 * @param inViewID TODO: Describe the Parameter 246 * @return TODO: Describe the Return Value 247 */ 248 public final Page findPageByID(String inViewID) { 249 if (pages == null) { 250 return null; 251 } 252 253 for (Iterator i = pages.iterator(); i.hasNext(); ) { 254 Object o = i.next(); 255 if (Debug.ON) { 256 Debug.assertTrue(o instanceof Page, "not Page: " + o); 257 } 258 if (((Page) o).equalsID(inViewID)) { 259 return (Page) o; 260 } 261 } 262 263 return null; 264 } 265 266 267 /*** 268 * For debug. 269 * 270 * @return TODO: Describe the Return Value 271 */ 272 public String toString() { 273 String result = "(Page:"; 274 if (pages != null) { 275 result += "," + pages.toString(); 276 } 277 result += ")"; 278 return result; 279 } 280 }

This page was automatically generated by Maven